#ifndef UPDATECHECKER_H
#define UPDATECHECKER_H

#include <QtNetwork/QNetworkReply>
#include <QtNetwork/QNetworkAccessManager>


class UpdateChecker : public QObject
{
	Q_OBJECT

public:
	UpdateChecker();
	~UpdateChecker();

	void beginToDownloadUpdateXML(const QString &updateXMLUrl);
	void beginToDownloadEXE(const QString &exeUrl);
	void runApplication();
	bool getApplicationVersion(int &version);

signals:
	void downloadEXEStarted();
	void downloadEXEProgress(qint64 bytesReceived, qint64 bytesTotal);
	void downloadEXEFinished();

protected slots:
	void endDownloadXML();
	void endDownloadEXE();
	void progressDownloadEXE(qint64 bytesReceived, qint64 bytesTotal);

protected:
	void abortXMLReply();
	void abortEXEReply();
	bool parseUpdateXml(QString updateXmlText, QString &updateUrl, int &version);
	QString getApplicationPath();

	QNetworkReply *downloadXMLReply, *downloadEXEReply;
	QNetworkAccessManager *networkManager;
	QString updateUrl;
	int updateVersion;
};

#endif